﻿@ModelType FiledWikiPageModel
@Code
    Dim PageTypeListItems As New SelectList(Wiki.WikiModel.Instance.PageTypesTagGroups.Keys, Model.PageType)
    Dim TagGroups As New HashSet(Of String)(WikiModel.Instance.PageTypesTagGroups(Model.PageType))
    For Each tagGroup In Model.Tags.Keys
        TagGroups.Add(tagGroup)
    Next
End Code

<script type="text/javascript" src="/scripts/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
    tinymce.init({
        selector: "textarea.tinymce",
        plugins: [
            "advlist autolink lists link image charmap",
            "searchreplace code fullscreen",// autoresize",
            "insertdatetime media table contextmenu heading"
        ],
        toolbar: "removeformat comment strikethrough underline italic bold | h2 h3 h4 | alignleft aligncenter alignright | indent outdent numlist bullist | link image | undo redo",
        menubar: "tools table format view insert edit",
        directionality: 'rtl',
        language: 'he_IL',
        target_list: false, link_title: false,
        browser_spellcheck: true,
        statusbar: false,
        invalid_elements: "h1, form, input, div",
        content_css: [@Styles.RenderFormat("""{0}"", ", "~/Content/css")],
        table_class_list: [{ title: 'Regular', value: 'table' }, { title: 'Striped', value: 'table table-striped' }, { title: 'Bordered', value: 'table table-bordered' }, ],
        table_row_class_list: [{ title: 'Regular', value: '' }, { title: 'Active', value: 'active' }, { title: 'Success', value: 'success' }, { title: 'Info', value: 'info' }, { title: 'Warning', value: 'warning' }, { title: 'Danger', value: 'danger' }],
        formats_merge: true,
        formats: {
            comment: { inline: 'span', classes: 'comment' }
        },
        style_formats: [
    {
        title: "כותרת", items: [
           { title: "כותרת ראשית", format: "h2" },
           { title: "כותרת משנה", format: "h3" },
           { title: "תת כותרת", format: "h4" },
           { title: "כותרת קטנה", format: "h5" },
        ]
    },
    {
        title: "עיצוב", items: [
           { title: "הערה", format: "comment" },
           { title: "ציטוט", format: "blockquote" },
           { title: "בלוק", format: "pre" },
           { title: "קוד", format: "code" },
           { title: "פסקה", format: "p" },
        ]
    },
        ],
        setup: function (editor) {
            editor.addButton('comment', {
                title: 'הערה',
                icon: "code",
                stateSelector: 'span.comment',
                onclick: function () {
                    editor.formatter.toggle("comment");
                }
            });
        },
    });
</script>

<h1>עריכת הדף '@Model.Title'</h1>

<ul class="action-menu">
    @If Model.IsCurrentVersion Then
        @<li>@Html.ActionLink("דף", "FetchExact", New With {.page = Model.Title})</li>
        @<li>@Html.ActionLink("היסטוריה", "History", New With {.page = Model.Title})</li>
        @<li>@Html.ActionLink("שינוי שם", "Rename", New With {.page = Model.Title})</li>
        @<li>@Html.ActionLink("מחיקה", "Delete", New With {.page = Model.Title})</li>
    Else
        @<li>@Html.ActionLink("דף עדכני", "FetchExact", New With {.page = Model.Title})</li>
        @<li>@Html.ActionLink("גרסת ארכיון", "FetchVersion", New With {.page = Model.Title, .version = Model.GetVersionCode()})</li>
        @<li>@Html.ActionLink("היסטוריה", "History", New With {.page = Model.Title})</li>
    End If

</ul>

<div class="row" style="margin-bottom: 40px">
    @Using Html.BeginForm("Edit", "Wiki", New With {.page = Model.Title}, FormMethod.Post)
        @Html.Hidden("UpdatedPage.Title", Model.Title)
        @Html.Hidden("UpdatedPage.DateModeified", Model.DateModeified)
        @Html.Hidden("UpdatedPage.VersionNumber", Model.VersionNumber)

        @<div class="col-lg-9 col-md-8 col-sm-7">
            <div class="spaced">
                @Html.TextArea("UpdatedPage.Content", Model.Content, New With {.class = "edit-content-field tinymce"})
            </div>
            <div class="editor-save-panel controls">
                <table>
                    <tr>
                        <td>
                            @Html.TextBox("UpdatedPage.LastChangeNotes", Model.LastChangeNotes, New With {.placeholder = "הערות שינוי", .class = "form-control"})
                        </td>
                        <td width="1%">
                            <button class="btn btn-default" type="submit" name="target" value="preview">תצוגה מקדימה</button>
                        </td>
                        <td width="1%">
                            <button class="btn btn-primary" type="submit" name="target" value="save">שמור</button>
                        </td>
                    </tr>
                </table>
            </div>
        </div>

        @<div class="col-lg-3 col-md-4 col-sm-5">
            <table>
                <tr>
                    <td>סוג הדף</td>
                    <td>@Html.DropDownList("UpdatedPage.PageType", PageTypeListItems, New With {.class = "form-control", .onchange = "this.form.submit()"})</td>
                </tr>
                <tr>
                    <td>שמות נוספים</td>
                    <td>@Html.TextArea("UpdatedPage.NamesString", Model.GetNonTitleNames().ToString, New With {.rows = "3", .class = "form-control"})</td>
                </tr>
                <tr>
                    <td>תמונה</td>
                    <td>@Html.TextBox("UpdatedPage.Picture", Model.Picture, New With {.class = "form-control"})</td>
                </tr>
                <tr class="spacer"></tr>
                <tr>
                    <td><label for="UpdatedPage_IsCategory">קטגוריה?</label></td>
                    <td>@Html.CheckBox("UpdatedPage.IsCategory", Model.IsCategory, New With {.class = "form-control large"})</td>
                </tr>
                <tr>
                    <th>תגיות</th>
                </tr>
                @For Each tagGroup In TagGroups
                    @<tr>
                        <td>@tagGroup</td>
                        <td>@Html.TextBox(String.Format("UpdatedPage.TagsStrings[{0}]", tagGroup), If(Model.Tags.ContainsKey(tagGroup), Model.Tags(tagGroup), ""), New With {.class = "form-control"})</td>
                    </tr>
        Next
            <tr>
                <td><label for="UpdatedPage_IsFavorite">סמן כמועדף</label></td>
                <td>@Html.CheckBox("UpdatedPage.IsFavorite", Model.IsFavorite, New With {.class = "form-control large"})</td>
            </tr>
                <tr class="spacer"></tr>
                <tr>
                    <th>מידע תזונתי</th>
                </tr>
                <tr>
                    <td colspan="2">@Html.TextArea("UpdatedPage.NutritionalData.NutritionalDataString", If(Model.NutritionalData IsNot Nothing, Model.NutritionalData.NutritionalDataString, ""), New With {.rows = "4", .class = "form-control"})</td>
                </tr>
                <tr>
                    <td>מספר מנות</td>
                    <td>@Html.TextBox("UpdatedPage.NutritionalData.NumberOfServings", If(Model.NutritionalData IsNot Nothing, Model.NutritionalData.NumberOfServings, ""), New With {.class = "form-control"})</td>
                </tr>
                <tr>
                    <td>תיאור מנה</td>
                    <td>@Html.TextBox("UpdatedPage.NutritionalData.ServingDescription", If(Model.NutritionalData IsNot Nothing, Model.NutritionalData.ServingDescription, ""), New With {.class = "form-control"})</td>
                </tr>

            </table>
        </div>
    End Using
</div>


@If ViewData("preview") Then
    @<div class="row page-content">
        <h1 id="preview">תצוגה מקדימה: @Model.Title</h1>

        @Html.Raw(MarkupTools.ProcessPageHtmlContent(Model.Content, Model, Html))
    </div>
End If
